﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yunwei.DAL;
using Yunwei.Domain.Models;
using Yunwei.IBizLogic;

namespace Yunwei.BizLogic
{
    public class DinnerTableService : BaseService<DinnerTable>, IDinnerTableService
    {
        public DinnerTableService():base(RepositoryFactory.DinnerTableRepository)
        {
        }
        public IQueryable<DinnerTable> FindList(int number, string name, int restaurant_Id, int orderCode)
        {
            return FindPageList(out number, 1, number, name, restaurant_Id, orderCode);
        }

        public IQueryable<DinnerTable> FindPageList(out int totalRecord, int pageIndex, int pageSize, string name, int restaurant_Id, int orderCode)
        {
            totalRecord = 0;
            if (restaurant_Id == 0) return null;

            IQueryable<DinnerTable> dts = CurrentRepository.Entities;
            if (!string.IsNullOrEmpty(name)) dts = dts.Where(cm => cm.Name.Contains(name));
            if (restaurant_Id > 0) dts = dts.Where(s => s.Restaurant_Id == restaurant_Id);

            dts = Order(dts, orderCode);
            totalRecord = dts.Count();

            return PageList(dts, pageIndex, pageSize).AsQueryable();
        }

        public IQueryable<DinnerTable> Order(IQueryable<DinnerTable> entitys, int orderCode)
        {
            switch (orderCode)
            {
                //默认排序
                default:
                    entitys = entitys.OrderBy(cm => cm.Name);
                    break;
            }
            return entitys;
        }
    }
}
